package UserInterface;

import javax.swing.JFormattedTextField;
import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;

import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;

import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.text.MaskFormatter;

public class PutNumberCard extends JPanel {
	private JFormattedTextField textField;
	private String s="";
	MaskFormatter formatter;

	/**
	 * Create the panel.
	 */
	
	private NumberPanel panelNumbers = new NumberPanel();
	private EditorsPanel panelEditors =new EditorsPanel();
	
	/*public JButton[] getBottons(){
		return panelNumbers.getButtons();
	}*/
	public void putNumbers(){
		JButton[] buttons =panelNumbers.getButtons();
		for(int i=0;i<buttons.length;i++){
			buttons[i].addActionListener(new Listen(buttons[i].getText()));
		}
	}
	class Listen implements ActionListener{
		String text="";
		Listen(String text){
			this.text=text;
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			if (s.length()<16)
			{
			s+=text;
			textField.setText(s);
			}
			
		}
		
	}
	
	public void clearS(){
		s="";
	}
	public String getS(){
		return s;
	}
	public void setS(String s){
		this.s=s;
		textField.setText(s);
	}
	public String getAcountNumber(){
		return textField.getText();
	}
	
	public void putListenerOk(ActionListener list){
		panelEditors.setOkListener(list);
	}
	public void putListenerCancel(ActionListener list){
		panelEditors.setCancelListener(list);
	}
	public void putListenerChange(ActionListener list){
		panelEditors.setChangeListener(list);
	}


	
	public PutNumberCard() {
		//panelEditors= new EditorsPanel();
	
		
		this.setSize(500, 500);
		setBackground(new Color(255, 248, 220));
		
		panelEditors.setBackground(new Color(255, 248, 220));
		
		
		JLabel lbl = new JLabel("Enter the card number: ");
		lbl.setForeground(new Color(128, 0, 0));
		lbl.setFont(new Font("Trebuchet MS", Font.BOLD | Font.ITALIC, 29));
		
		try {
			formatter = new MaskFormatter("####-####-####-####");
			//formatter.setPlaceholderCharacter('_');
		   
		textField = new JFormattedTextField(formatter);
		textField.setFont(new Font("Tahoma", Font.BOLD, 19));
		textField.setColumns(10);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	     
	     GroupLayout groupLayout = new GroupLayout(this);
	     groupLayout.setHorizontalGroup(
	     	groupLayout.createParallelGroup(Alignment.TRAILING)
	     		.addGroup(groupLayout.createSequentialGroup()
	     			.addGap(27)
	     			.addComponent(panelNumbers, GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE)
	     			.addGap(18)
	     			.addComponent(panelEditors, GroupLayout.PREFERRED_SIZE, 136, GroupLayout.PREFERRED_SIZE)
	     			.addContainerGap())
	     		.addGroup(groupLayout.createSequentialGroup()
	     			.addGap(129)
	     			.addComponent(textField)
	     			.addGap(121))
	     		.addGroup(groupLayout.createSequentialGroup()
	     			.addContainerGap(115, Short.MAX_VALUE)
	     			.addComponent(lbl)
	     			.addGap(136))
	     );
	     groupLayout.setVerticalGroup(
	     	groupLayout.createParallelGroup(Alignment.LEADING)
	     		.addGroup(groupLayout.createSequentialGroup()
	     			.addGap(30)
	     			.addComponent(lbl)
	     			.addGap(42)
	     			.addComponent(textField, GroupLayout.PREFERRED_SIZE, 42, GroupLayout.PREFERRED_SIZE)
	     			.addGap(38)
	     			.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
	     				.addComponent(panelEditors, GroupLayout.PREFERRED_SIZE, 182, GroupLayout.PREFERRED_SIZE)
	     				.addComponent(panelNumbers, GroupLayout.PREFERRED_SIZE, 198, GroupLayout.PREFERRED_SIZE))
	     			.addContainerGap(115, Short.MAX_VALUE))
	     );
	     setLayout(groupLayout);
	

	
	
}}
